package Algorithm;



//1代表防守，0代表进攻
import java.util.*;

public class Main {
    public static void main(String[] args) {

        //想用贪心做，但时间不赶趟了，不知道了，不做了！
        Scanner scanner=new Scanner(System.in);
        int n = scanner.nextInt();
        int money=scanner.nextInt();
        int[] temp=new int[n];
        for (int i=0;i<n;i++)
            temp[i]=scanner.nextInt();

        int count=0;
        int i=0;
        while (i< temp.length){
            int flag=-1;
            for (int j=i+1;j< temp.length;j++){
                if (temp[j]> temp[i]){
                    flag=j;
                    break;
                }
            }
            if (flag==-1){
                i++;
            }else {
                while (i!=flag&&(money> temp[i])){
                    money-=temp[i];
                    i++;
                    count++;
                }
                i=flag;
                if (count>0) {
                    money += temp[flag];
                    count--;
                }
            }
        }
        System.out.println(money+count* temp[temp.length-1]);
    }


    public int getNumber (int[] a) {
        // write code here
        int[] res=a;
        while ((res=delete(res)).length!=1){}
        return res[0];
    }

    public int[] delete(int[] temp){
        if (temp.length==1)
            return new int[]{temp[0]};
        int len=temp.length;
        boolean[] flag=new boolean[len];
        int count=len;
        for (int i=0;i<temp.length;i++){
            if (!dis(i+1)) {
                flag[i] = true;
                count--;
            }
        }
        int[] res=new int[count];
        int i=0;
        for (int j=0;j< flag.length;j++){
            if (!flag[j]){
                res[i]= temp[j];
                i++;
            }
        }
        return res;
    }

    public boolean dis(int num){
        if (num==1) return false;
        for (int i=2;i<num;i++){
            if (num%i==0)
                return false;
        }
        return true;
    }

    public int majorityElement(int[] nums) {
        if (nums.length==1) return nums[0];
        int left=0;
        int right=nums.length-1;
        int mid=right>>1;
        int paration = paration(nums, left, right);
        while (paration!=mid){
            if (paration<mid){
                left=mid+1;
                paration=paration(nums,left,right);
            }else {
                right=mid-1;
                paration=paration(nums,left,right);
            }
        }
        return nums[paration];
    }

    public int paration(int[] nums,int left,int right){
        int random=left+(int)((right-left+1)*Math.random());
        swap(nums,random,right);
        int base=nums[right];
        int bound=left-1;
        int i=left;
        while (i<right){
            if (nums[i]<nums[right]){
                if (i!=bound+1){
                    swap(nums,bound+1,i);
                    bound++;
                }else {
                    bound++;
                }
                i++;
            }else {
                i++;
            }
        }
        swap(nums,bound+1,right);
        return bound+1;
    }

    public void swap(int[] arr,int a,int b){
        int temp=arr[a]^arr[b];
        arr[a]=temp^arr[a];
        arr[b]=temp^arr[b];
    }

    public int[] getLeastNumbers(int[] arr, int k) {
            PriorityQueue<Integer> priorityQueue=new PriorityQueue<>((o1,o2)->{
                return o2-o1;
            });
            for (int i=0;i<arr.length;i++){
                if (priorityQueue.size()<k){
                    priorityQueue.offer(arr[i]);
                }else {
                    Integer peek = priorityQueue.peek();
                    if (peek>arr[i]){
                        priorityQueue.poll();
                        priorityQueue.offer(arr[i]);
                    }
                }
            }
            int[] res=new int[k];
            int i=0;
            while (priorityQueue.size()!=0){
                res[i++]=priorityQueue.poll();
            }
            return res;
    }

    public int maxSubArray(int[] nums) {
        if (nums.length==1) return nums[0];
        int[] dp=new int[nums.length];
        dp[0]=nums[0];
        int max=dp[0];
        for (int i=1;i<nums.length;i++){
            dp[i]=Math.max(dp[i-1]+nums[i],nums[i]);
            max=Math.max(max,dp[i]);
        }
        return max;
    }

    class Node {
        public int val;
        public Node left;
        public Node right;

        public Node() {}

        public Node(int _val) {
            val = _val;
        }

        public Node(int _val,Node _left,Node _right) {
            val = _val;
            left = _left;
            right = _right;
        }
    };

    Node head=null;
    Node pre=null;
    public Node treeToDoublyList(Node root) {
            if (root==null)
                return null;
            help(root);
            head.right=pre;
            pre.left=head;
            return head;
    }
    public void help(Node node){
        if (node==null)
            return;
        help(node.left);
        if (head==null){
            head=node;
            pre=node;
        }else{
            pre.right=node;
            node.left=pre;
            pre=pre.right;
        }
        help(node.right);
    }


}
